﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
namespace GUI
{
    public partial class LoaiPhong : Form
    {
        public LoaiPhong()
        {
            InitializeComponent();
            List<DTO_LoaiPhong> llp = new List<DTO_LoaiPhong>();
            llp = BUS_LoaiPhong.LayTatCaPhong();
            int i = 0;
            GirdView.Rows.Add(llp.Count);
            foreach (DTO_LoaiPhong lp in llp)
            {
                GirdView[1, i].Value = lp.MaLoaiPhong;
                GirdView[2, i].Value = lp.TenLoaiPhong;
                GirdView[3, i].Value = lp.DonGia.ToString();
                i++;
            }
        }

        private void Them_Click(object sender, EventArgs e)
        {
            try
            {
                int temp = 1;
                //string null_value = "";
                if (string.Compare(txt_Loai.Text, "") == 0)
                {
                    temp = 0;
                    MessageBox.Show("Thông tin chưa đầy đủ, Chưa nhập Loại phòng!!!");
                }
                if (string.Compare(txt_Ten.Text, "") == 0)
                {
                    temp = 0;
                    MessageBox.Show("Thông tin chưa đầy đủ, Chưa nhập Tên Loại phòng!!!");
                }
                if (string.Compare(txt_DonGia.Text, "") == 0)
                {
                    temp = 0;
                    MessageBox.Show("Thông tin chưa đầy đủ, Chưa nhập Đơn giá!!!");
                }
                if (temp == 1)
                {
                    DTO_LoaiPhong lp = new DTO_LoaiPhong();
                    lp.MaLoaiPhong = txt_Loai.Text;
                    lp.TenLoaiPhong = txt_Ten.Text;
                    lp.DonGia = Double.Parse(txt_DonGia.Text);

                    BUS_LoaiPhong.ThemLoaiPhong(lp);
                    //cap nhap lai thong tin
                    GirdView.Rows.Clear();
                    List<DTO_LoaiPhong> llp = new List<DTO_LoaiPhong>();
                    llp = BUS_LoaiPhong.LayTatCaPhong();
                    int i = 0;
                    GirdView.Rows.Add(llp.Count);
                    foreach (DTO_LoaiPhong lpx in llp)
                    {
                        GirdView[1, i].Value = lpx.MaLoaiPhong;
                        GirdView[2, i].Value = lpx.TenLoaiPhong;
                        GirdView[3, i].Value = lpx.DonGia.ToString();
                        i++;
                    }
                    txt_DonGia.Text = "";
                    txt_Loai.Text = "";
                    txt_Ten.Text = "";
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void Xoa_Click(object sender, EventArgs e)
        {
            int index = GirdView.SelectedRows[0].Index;
            DTO_LoaiPhong lp = new DTO_LoaiPhong();
            lp.MaLoaiPhong = GirdView[1, index].Value.ToString();
            BUS_LoaiPhong.XoaLoaiPhong(lp);
            //cap nhap lai thong tin
            GirdView.Rows.Clear();
            List<DTO_LoaiPhong> llp = new List<DTO_LoaiPhong>();
            llp = BUS_LoaiPhong.LayTatCaPhong();
            int i = 0;
            GirdView.Rows.Add(llp.Count);
            foreach (DTO_LoaiPhong lpx in llp)
            {
                GirdView[1, i].Value = lpx.MaLoaiPhong;
                GirdView[2, i].Value = lpx.TenLoaiPhong;
                GirdView[3, i].Value = lpx.DonGia.ToString();
                i++;
            }
        }
    }
}
